package com.example.rotateimageview.drable

import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable

/**
 * author  : Liushuai
 * time    : 2021/12/5 17:10
 * desc    :
 */

class CustomDrawable :Drawable(){

    private val paint =Paint(Paint.ANTI_ALIAS_FLAG)
    override fun draw(canvas: Canvas) {

    }

    override fun setAlpha(alpha: Int) {
        paint.alpha= alpha
    }

    override fun setColorFilter(colorFilter: ColorFilter?) {
        paint.colorFilter =colorFilter
    }

    /**
     * 透明度
     */
    override fun getOpacity(): Int {
        return when (paint.alpha) {
                  0-> PixelFormat.TRANSPARENT
                  0xff -> PixelFormat.OPAQUE
              else -> PixelFormat.TRANSLUCENT
        }
    }
}